package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie.entity.DishFlavor;
import com.itheima.reggie.mapper.DishFlavorMapper;
import com.itheima.reggie.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DishFlavorServiceImpl implements DishFlavorService {
    @Autowired
    private DishFlavorMapper mapper;

    @Override
    public int add(DishFlavor dishFlavor) {
        return mapper.insert(dishFlavor);
    }

    /**
     * 根据菜品id查询这个菜品的口味数据
     *
     * @param dishId
     */
    @Override
    public List<DishFlavor> findByDishId(long dishId) {
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId,dishId);
        return mapper.selectList(lqw);
    }

    /**
     * 根据菜品id删除这个口味的数据
     *
     * @param dishId
     */
    @Override
    public int delete(long dishId) {
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId,dishId);
        return mapper.delete(lqw);
    }

    /**
     * 根据DishId
     * @param id
     */
    @Override
    public int deleteByDishId(Long id) {
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getId,id);
        return mapper.delete(lqw);
    }
}
